jQuery(document).ready(function($) {
    var $mainContent = $("#content"),
        siteUrl = "http://" + top.location.host.toString(),
        url = ''; 
    var $breadcrumbs = $("#breadcrumbs");
    $(document).delegate("a[href^='"+siteUrl+"']:not([href*=/wp-admin/]):not([href*=/wp-content/]):not([href*=/wp-login.php]):not([href$=/feed/])", "click", function() {
        location.hash = this.pathname;
        return false;
    }); 
 
    $("#searchform").submit(function(e) {
        location.hash = '?s=' + $("#s").val();
        e.preventDefault();
    }); 
 
    $(window).bind('hashchange', function(){
        url = window.location.hash.substring(1); 
 
        if (!url) {
            return;
        } 
		$(".menu-top a").removeClass("active");
		$(".menu-r a").removeClass("active");
		if(url=="/") $(".home-url").addClass("active");
		else if(url=="/services") $(".services-url").addClass("active");
		else if(url=="/technologies") $(".technologies-url").addClass("active");
		else if(url=="/contactus") $(".contactus-url").addClass("active");
		else if(url=="/whynovaitech") $(".whynovaitech a").addClass("active");
		else if(url=="/businessmodels") $(".businessmodels a").addClass("active");
		else if(url=="/sampleprojects") $(".sampleprojects a").addClass("active");
		else if(url=="/clients") $(".clients a").addClass("active");
		//else if(url=="/employment") {$(".employment-url").addClass("active");};
		url = url + " #content";  
		
		$mainContent.html('<p><img src="'+baseURL+'/images/ajax-loader.gif"/></p>').load(url, function() {
				var slidepage=$("#pageslide").val();
				var pageid=$("#pageid").val();
				$("a.single_image").fancybox();
				$breadcrumbs.html($("#hidden_breadcrumbs").html());
				if(slidepage == "down" || slidepage == ""){
					$(".box-support").css("position","relative");
					$(".box-support").css("left","0px");
					$mainContent.css("margin","-570px 0 0");
					$mainContent.delay(100).animate({
					  margin: 0
					},1500,function() {
						//$mainContent.css("margin","0");
					});
				}else{
					$(".box-support").css("position","absolute");
					$(".box-support").css("left","495px");
					$mainContent.css("margin","0 478px");
					$mainContent.delay(100).animate({
					  margin: 0
					},1500,function() {
						$mainContent.css("margin","0");
					});
				}
				$( '.iwacontact' ).iwacontactForm();
				$(".iwacontact #reset").removeAttr("disabled");
				$(".iwacontact #reset").click(function(){
					$(".iwacontact").find("input").each(function(){
						$(this).removeAttr("disabled");
					});
					$(".iwacontact").find("textarea").each(function(){
						$(this).removeAttr("disabled");
					});
					$(".iwacontact").find("select").each(function(){
						$(this).removeAttr("disabled");
					});
					$(".attachmentarr").each(function(){
						$(this).parent().remove();
					});
				});
				 $(".toogleSlide").each(function(){
						$("#"+$(this).attr("name")).css("display","none");
					})
				$(".toogleSlide").click(function(){
					var t=$(this);
					$(this).parent().parent().find(".toogleSlide").each(function(){
							if($(this)!=t)
								$("#"+$(this).attr("name")).slideUp("slow");
					});
					if($("#"+t.attr("name")).css("display")=="none")
						  $("#"+$(this).attr("name")).slideToggle("slow");
				});
				//contact script
				$("#upload_ajax").click(function()
				{
					if(!$("#userfile").val()){
						alert("You did not select a file to upload.");
						return;
					}		
					$("#loading")
					.ajaxStart(function(){
						$(this).show();
					})
					.ajaxComplete(function(){
						$(this).hide();
					});

					$.ajaxFileUpload
					(
						{
							url:"/wp-content/plugins/ajax-contact/doajaxfileupload.php",
							secureuri:false,
							fileElementId:"userfile",
							dataType: "json",
							data:{name:"logan", id:"id",boolCapture:$("#boolCapture").val()},
							success: function (data, status)
							{
								var str="<p id=\'"+data.id+"\'><input type=\'hidden\' class=\'attachmentarr\' name=\'attachment[]\' value=\'"+data.filename+"\'/><span style=\"clear:both;\"><span class=\'delfile\' style=\"color:red;padding:5px;cursor:pointer;\">x</span>"+data.filename+"</span></p>";
								$("#upload_ajax").after(str).show("slow");
								$(".delfile").click(function(){
									$.ajax({
										type: "post",
										url: "/wp-content/plugins/ajax-contact/delfile.php",
										data: "filename="+data.filename+"&id="+data.id,
										success: function(data){
											$("#"+data).remove();
										},
										statusCode:{
											404: function(){
												
											}
										}
									});
								});
								console.log(data);
							},
							error: function (data, status, e)
							{
								alert(e);
							}
						}
					)
					
					return false;

				});
				
				//end contact script
			});
    });
 
    $(window).trigger('hashchange');
});

